package ${initProjectVo.packageName}.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import ${initProjectVo.packageName}.entity.UserInfo;
import ${initProjectVo.packageName}.dto.UserInfoDTO;
import ${initProjectVo.packageName}.mapper.UserInfoMapper;
import ${initProjectVo.packageName}.service.IUserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Faye.Wang
 * @version 1.0
 * @date 2021/3/31 10:26
 * @Description
 */
@Service
public class IUserInfoServiceImpl implements IUserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public UserInfo loadUserInfoByName(String userName) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",userName);
        UserInfo userInfo = userInfoMapper.selectOne(queryWrapper);
        return userInfo;
    }

    @Transactional(readOnly = false,rollbackFor = Exception.class,propagation= Propagation.REQUIRED)
    @Override
    public void insertUser(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Transactional(readOnly = false,rollbackFor = Exception.class,propagation= Propagation.REQUIRED)
    @Override
    public void updateUserProfile(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Transactional(readOnly = false,rollbackFor = Exception.class,propagation= Propagation.REQUIRED)
    @Override
    public void deletePrimaryKey(Integer id) {
        userInfoMapper.deleteById(id);
    }
    @Override
    public IPage<UserInfoDTO> selectEntityList(Page<UserInfoDTO> page, UserInfo entity) {
        Map<String,Object> params = new HashMap<>();
        return userInfoMapper.selectEntityList(page,params);
    }
    @Override
    public UserInfoDTO getUserEntityById(Integer id) {
        Map<String,Object> params = new HashMap<>();
        params.put("userId",id);
        return userInfoMapper.getUserEntityById(params);
    }
}
